package net.dgg.dggcloud.service.jrcrm.utils;

import net.dgg.dggcloud.core.util.DateUtil;
import net.dgg.dggcloud.service.jrcrm.entity.customer.WhiteList;
import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;

import java.io.Serializable;
import java.util.Date;
import java.util.Iterator;

/**
 * 白名单客户使用实体更新sql表名拦截替换
 * @ClassName: CustomerIntercept
 * @Author: 周潮
 * @Date: 2017年11月29 20:40:31
 * @Version V1.0
 */


public class CustomerIntercept extends EmptyInterceptor{

    //目标表明
    private String targetTableName;
    //替换后表名
    private String replaceTableName;

    @Override
    public String onPrepareStatement(String sql) {
        //替换表名，例如："cus_white_list"-------->>>"cus_white_list_201711"
        if(sql.contains(targetTableName)){
            sql = sql.replaceAll(targetTableName, replaceTableName);
        }
        return sql;
    }

    public CustomerIntercept(String targetTableName, String replaceTableName) {
        this.targetTableName = targetTableName;
        this.replaceTableName = replaceTableName;
    }
}
